<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:comps="http://java.sun.com/jsf/composite/components">

<h:panelGrid columns="3" columnClasses="topAlign, topAlign, topAlign">
	
	<p:panel header="#{locale['crud.cadastro.titulo']}">
			
		<h:form id="enqueteForm">
																				
			<p:commandButton id="cadastrarBtn"
				icon="ui-icon-document"
				styleClass="ui-priority-primary"
				update=":tabView:insercaoEnqueteForm" 
				value="#{locale['crud.botao.cadastrar']} Enquete"
				action="#{AdminEnqueteBean.prepararInsercao()}"
				tabindex="1" />
					
		</h:form>
						
	</p:panel>
	
	<p:spacer style="width: 10px" />
						
	<p:panel header="Enquetes" style="width: 740px;">
	
		<h:form id="listagemEnqueteForm">
					
			<p:dataTable id="registros" var="registro"
				styleClass="dataTableListagem"
				widgetVar="enqueteTable"
				value="#{AdminEnqueteBean.enquetes}"
				paginator="true" rows="12"
				paginatorPosition="bottom"
				paginatorAlwaysVisible="true"
				tableStyleClass="tableListagem"
				emptyMessage="#{locale['crud.pesquisa.lista.semResultado']}">
												
				<p:column sortBy="#{registro.codigo}">
								
					<f:facet name="header">
						<h:outputText style="padding: 0px 5px 0px 5px;" value="Cod" />
					</f:facet>
					<h:outputText value="#{registro.codigo}" />
				
				</p:column>				
		
				<p:column sortBy="#{registro.titulo}">
								
					<f:facet name="header">
						<h:outputText 
							style="padding: 0px 10px 0px 10px;"
							value="#{locale['paginaInterna.label.titulo']}" />
					</f:facet>
					<h:panelGroup layout="block" style=" width: 150px;">
						<h:outputText value="#{registro.titulo}" />
					</h:panelGroup>
				
				</p:column>
																		
				<p:column styleClass="alignCenter">
							
					<f:facet name="header">
						<h:outputText value="#{locale['crud.pesquisa.lista.acoes']}"
							styleClass="dataTableTextoColunaCabecalho" />
					</f:facet>
					
					<h:panelGroup layout="block" style="width: 70px; align: center;">
		
						<p:commandButton icon="ui-icon-pencil"
							disabled="true"
							title="#{locale['crud.botao.editar']}"
							action="#{AdminEnqueteBean.prepararEdicao(registro)}"
							update=":tabView:edicaoEnqueteForm"
							oncomplete="edicaoEnqueteDlg.show()" />
						
						<p:spacer width="5" />
									
						<p:commandButton icon="ui-icon-trash"
							title="#{locale['crud.botao.excluir']}"
							action="#{AdminEnqueteBean.prepararExclusao(registro)}" />						
										
					</h:panelGroup>
										
				</p:column>
													
			</p:dataTable>
							
		</h:form>	
			
	</p:panel>
			
</h:panelGrid>		
		
<p:dialog appendToBody="true"
	position="414, 50"
	widgetVar="insercaoEnqueteDlg"
	modal="true" showEffect="fade" hideEffect="fade"
	resizable="false" closable="false" draggable="false">
	
	<f:facet name="header">
		<h:outputFormat id="tituloInsercaoEnquete" value="#{locale['insercao.titulo']}">
			<f:param value="Enquete" />
		</h:outputFormat>							
	</f:facet>
		
	<h:form id="insercaoEnqueteForm">
		
		<h:panelGroup layout="block">
			<p:messages id="insercaoEnqueteMsg" closable="true" />
		</h:panelGroup>
		
		<h:panelGrid columns="2">
			
			<p:outputLabel id="tituloInsLbl"
				for="tituloIns" value="#{locale['enquete.label.titulo']}" />
			<p:inputText id="tituloIns" value="#{AdminEnqueteBean.enquete.titulo}"
				label="#{locale['paginaInterna.label.titulo']}"
				onkeypress="limparEspacosExtras(this);"
				onblur="trim(this);"
				style="width: 400px;"
				maxlength="200"
				required="true">
			</p:inputText>
			
		</h:panelGrid>
		
		<h:panelGroup layout="block" style="margin-top: 10px; margin-bottom: 10px;">
		
			<h:panelGrid columns="7">

				<p:outputLabel value="Opção: " for="textoEnqueteOpcao" />
				<p:spacer width="10" />
				<p:inputText id="textoEnqueteOpcao" required="true"
				    style="width: 290px"
					value="#{AdminEnqueteBean.enqueteOpcao.textoOpcao}" />
				
				<p:spacer width="10" />
				
	            <p:commandButton id="adicionarOpcao" 
	            	icon="ui-icon-plus"
	            	value="Adicionar" update=":tabView:insercaoEnqueteForm:opcoesTable :tabView:insercaoEnqueteForm"  
					action="#{AdminEnqueteBean.reinit()}" >  
	                <p:collector 
	                	value="#{AdminEnqueteBean.enqueteOpcao}"   
						addTo="#{AdminEnqueteBean.enquete.enqueteOpcoes}" />  
	            </p:commandButton>
            
            </h:panelGrid>
            
           	<p:spacer width="300" height="10" />
           	            
		    <p:outputPanel id="opcoes">  
		        <p:dataTable id="opcoesTable" 
		        	rows="5" paginator="true" paginatorPosition="top" paginatorAlwaysVisible="true"
		        	value="#{AdminEnqueteBean.enquete.enqueteOpcoes}" var="enqueteOpcao">  
		  
		            <p:column width="320">  
		                <f:facet name="header">  
			                    <h:outputText value="Opção" />  
		                </f:facet>  
		                <h:outputText value="#{enqueteOpcao.textoOpcao}" />  
		            </p:column>  
		  
		            <p:column width="70">  
		                <f:facet name="header">  
		                    <h:outputText value="Operação" />  
		                </f:facet>
		                
		                <h:panelGroup layout="block" style="text-align: center;">
		                
			                <p:commandButton disabled="true"
			                	icon="ui-icon-pencil" type="button" />
			                	
			                <p:spacer width="5" />
			                
			                <p:commandButton icon="ui-icon-trash"
			                	update=":tabView:insercaoEnqueteForm:opcoesTable"
			                	action="#{AdminEnqueteBean.removerOpcao(enqueteOpcao)}" />
		                	
		                </h:panelGroup>
		                
		            </p:column>
		  
		        </p:dataTable>
		        
		    </p:outputPanel>              		
			
		</h:panelGroup>
		
		<h:panelGroup columns="2" 
			layout="block" 
			style="text-align: right; margin-top: 10px; border-top: dotted 1px; padding-top: 10px;">

			<p:commandButton id="salvarIns" value="#{locale['crud.botao.salvar']}"
				icon="ui-icon-disk"
				action="#{AdminEnqueteBean.salvarInsercao()}"
				styleClass="ui-priority-primary left"
				update="insercaoEnqueteForm" />
				
			<p:commandButton id="cancelarIns" value="#{locale['crud.botao.fechar']}"
				icon="ui-icon-close"
				action="#{AdminEnqueteBean.cancelarInsercao()}"
				styleClass="right"				
				immediate="true" />
			
		</h:panelGroup>
				
	</h:form>
	
</p:dialog>

<p:dialog appendToBody="true"
	widgetVar="edicaoEnqueteDlg"
	modal="true" showEffect="fade" hideEffect="fade"
	resizable="false" draggable="false" closable="false">
	
	<f:facet name="header">
		<h:outputFormat value="#{locale['edicao.titulo']}">
			<f:param value="#{locale['enquete.titulo']}" />
		</h:outputFormat>
	</f:facet>
	
	<h:form id="edicaoEnqueteForm">
	
		<h:panelGroup layout="block">
			<p:messages id="insercaoEnqueteMsg" closable="true" />
		</h:panelGroup>
		
		<h:panelGrid columns="2">
			
			<p:outputLabel id="tituloEdcLbl"
				for="tituloEdc" value="#{locale['paginaInterna.label.titulo']}" />
			<p:inputText id="tituloEdc" value="#{AdminEnqueteBean.enquete.titulo}"
				label="#{locale['paginaInterna.label.titulo']}"
				onkeypress="limparEspacosExtras(this);"
				onblur="trim(this);"
				style="width: 400px;"
				maxlength="200"
				required="true">
			</p:inputText>
			
		</h:panelGrid>
		
		<h:panelGroup layout="block" 
			style="text-align: right; margin-top: 10px; border-top: dotted 1px; padding-top: 10px;">
			
			<p:commandButton id="salvarEdc" value="#{locale['crud.botao.salvar']}"
				icon="ui-icon-disk"
				styleClass="ui-priority-primary left"
				action="#{AdminEnqueteBean.salvarEdicao()}"
				update="edicaoEnqueteForm" />
					
			<p:commandButton id="cancelarEdc" value="#{locale['crud.botao.fechar']}"
				icon="ui-icon-close"
				action="#{AdminEnqueteBean.cancelarEdicao()}"
				update="edicaoEnqueteForm" />
							
		</h:panelGroup>
		
	</h:form>
	
</p:dialog>

<comps:confirmacao
	tituloDialogo="#{locale['crud.alteracoes.titulo']}"
	widgetVar="confirmaAlteracoesEdicaoEnqueteDlg"
	simAction="#{AdminEnqueteBean.salvarEdicaoConfirmar()}"
	naoAction="#{AdminEnqueteBean.salvarEdicaoCancelar()}"
	simUpdate=":tabView:listagemEnqueteForm :indexGrowl" 
	naoUpdate=""
	scriptOnComplete="confirmaAlteracoesEdicaoEnqueteDlg.hide()">
	
	<f:facet name="mensagemDialogo">
	
		<h:outputFormat value="#{locale['crud.alteracoes.pergunta.edicao']}">
			<f:param value="#{locale['enquete.titulo']}" />
		</h:outputFormat>	
			
	</f:facet>
	
</comps:confirmacao>

<comps:confirmacao tituloDialogo="#{locale['crud.excluir.titulo']}"
	widgetVar="confirmaExclusaoEnqueteDlg"
	simAction="#{AdminEnqueteBean.excluirConfirmar()}"
	naoAction="#{AdminEnqueteBean.excluirCancelar()}"
	simUpdate=":tabView:listagemEnqueteForm :indexGrowl" 
	naoUpdate=":indexGrowl"
	scriptOnComplete="confirmaExclusaoEnqueteDlg.hide()">
	
	<f:facet name="mensagemDialogo">
	
		<h:outputFormat id="registroExclusao" value="#{locale['crud.excluir.pergunta']}">
			<f:param value="#{locale['enquete.titulo']}" />
		</h:outputFormat>
		
	</f:facet>
		
</comps:confirmacao>
	
</ui:composition>